package edu.gatech.cs4400.spring2014.A8.control;

/**
 * Static reference for the waitFor method. Used to block
 *  a thread until the lock forces a wake and the condition
 *  is met.
 *  
 * @author Stephen
 */
public abstract class Waiter {
	/**
	 * Method to block thread's execution until lock is released.
	 *  Used by control objects while waiting for GUI input.
	 * @param lock WaitedOn object to block for. 
	 */
	public static void waitFor(WaitedOn lock) {
		while (!lock.isDone()) {
			try {
				synchronized(lock) {
					lock.wait();
				}
			} 
			catch (InterruptedException e) {
				System.out.println("Lock interrupted!");
				e.printStackTrace();
				System.exit(-1);
			}
		}
	}
}
